package com.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.model.ReponseDto;
import com.model.SysUser;
import com.service.ISysUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = "/user")
@Api(tags = "系统管理员", value = "系统管理员相关api")
public class UserController {

    @Autowired
    private ISysUserService sysUserService;

    @RequestMapping(value = "/list")
    @ApiOperation(value = "用户列表")
    @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "用户名", required = false),
            @ApiImplicitParam(name = "roleId", value = "角色", required = false),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = false)})
    public ReponseDto<PageInfo> list(Model model, HttpServletRequest request, String name, Integer roleId,
            String pageNo, Integer pageSize) {
        return sysUserService.list(name, roleId, pageNo,pageSize);
    }

    @RequestMapping(value = "/update")
    @ApiOperation(value = "用户编辑")
    @ApiImplicitParams({})
    public ReponseDto<String> update(Model model, HttpServletRequest request, @RequestBody SysUser sysuser,
            @RequestHeader String userId, @RequestHeader String username) {
        return sysUserService.edit(sysuser, userId, username);
    }

    @RequestMapping(value = "/delete")
    @ApiOperation(value = "用户删除")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户名ID", required = true) })
    public ReponseDto<String> delete(Model model, HttpServletRequest request, Integer id, @RequestHeader String userId,
            @RequestHeader String username) {
        return sysUserService.delete(id, userId, username);
    }
}
